﻿using JBeamLibrary.VehicleParts.Elements;
using JBeamLibrary.VehicleParts.Enums;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JBeamLibrary.VehicleParts.Collections
{
    public class ElementPropertyCollection : KeyedCollection<ElementProperties, ElementProperty>
    {
        #region Properties

        /// <summary>Gets the index of the element holding the properties</summary>
        public int ElementIndex
        {
            get;
            private set;
        }

        /// <summary>Gets properties that define groups (group, deformGroup, breakGroup, ...)</summary>
        public IEnumerable<ElementProperty> GroupingProperties
        {
            get { return this.Where(prop => prop.Use == ElementPropertyUse.Group && prop.Name.EndsWith("Group")); }
        }

        /// <summary>Gets properties applying to multiple elements</summary>
        public IEnumerable<ElementProperty> GroupProperties
        {
            get { return this.Where(prop => prop.Use == ElementPropertyUse.Group); }
        }

        /// <summary>Gets properties applying to a single element</summary>
        public IEnumerable<ElementProperty> InlineProperties
        {
            get { return this.Where(prop => prop.Use == ElementPropertyUse.Single); }
        }

        #endregion

        #region CTORs

        public ElementPropertyCollection(int elementIndex)
        {
            ElementIndex = elementIndex;
        }

        #endregion

        #region KeyedCollection

        protected override ElementProperties GetKeyForItem(ElementProperty item)
        {
            return item.Property;
        }

        #endregion
    }
}
